
package com.aris.voicechecking;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class StudingModeActivity extends ActionBarActivity {

    protected Button bt_studing;

    private RelativeLayout adView;

    private WebView description_content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_studing_mode);

        initial();
        execution();
    }

    private void initial() {
        bt_studing = (Button)findViewById(R.id.bt_studing);
        adView = (RelativeLayout)findViewById(R.id.adView);
        description_content = (WebView)findViewById(R.id.description_content);
    }

    private void execution() {
        bt_studing.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent lessonIntent = new Intent(StudingModeActivity.this, WeekLessonActivity.class);
                startActivity(lessonIntent);
                overridePendingTransition(R.drawable.anim_slide_in_left,
                        R.drawable.anim_slide_out_left);
            }
        });

        adView.setBackgroundResource(R.drawable.banner);

        adView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent webviewIntent = new Intent(StudingModeActivity.this, WebviewActivity.class);
                startActivity(webviewIntent);
                overridePendingTransition(R.drawable.anim_slide_in_left,
                        R.drawable.anim_slide_out_left);

            }
        });

        configWebview();

        // actionbar

        ActionBar actionBar = getSupportActionBar();
        ColorDrawable colorDrawable = new ColorDrawable(getResources().getColor(R.color.main_color));
        actionBar.setBackgroundDrawable(colorDrawable);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_HOME_AS_UP);
        View actionbarcustomeview = getLayoutInflater().inflate(R.layout.actionbar_center_title,
                (ViewGroup)(getSupportActionBar().getCustomView()));

        TextView center_title = (TextView)actionbarcustomeview.findViewById(R.id.center_title);
        center_title.setText(getString(R.string.title_activity_studing_mode));
        center_title.setTextColor(Color.WHITE);

        actionBar.setCustomView(actionbarcustomeview, new ActionBar.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.MATCH_PARENT,
                Gravity.CENTER));
    }

    private void configWebview() {

        String html = "<html><style>body{font-size: 13px}</style><body style=\"background:transparent\">"
                + getString(R.string.studing_mode_str) + "</body></html>";
        String mime = "text/html";
        String encoding = "utf-8";

        description_content.loadDataWithBaseURL(null, html, mime, encoding, null);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.studing_mode, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            onBackPressed();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        overridePendingTransition(R.drawable.anim_slide_in_right, R.drawable.anim_slide_out_right);
    }
}
